package com.yun.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.yun.Model.User;
import com.yun.service.UserDaoImpl;

public class UserController extends ActionSupport implements ModelDriven<User>{

	private User user=null;
	List<User> userlist=new ArrayList<User>();
	
	public List<User> getUser(){
		return userlist;
	}
	
	public void setUser(List<User> userlist){
	    this.userlist=userlist;	
	}
	
	public String add() throws IOException{
		UserDaoImpl userdaoimpl=new UserDaoImpl();
		userdaoimpl.addUser(user);
		return "add";
	}
	
	public String getAllUsers() throws IOException{
		UserDaoImpl userdaoimpl=new UserDaoImpl();
		List<User> userlist=userdaoimpl.getAllUser();
		
		Map request=(Map)ActionContext.getContext().get("request");
		request.put("userlist", userlist);
		return "success";
	}
	
	public User getModel() {
		if(user==null){
			user=new User();
		}
		return user;
	}

	
}
